      SUBROUTINE INTRP0(X,XDOT,K,L,HH,N,TI,XI,XDOTI,CFPOS,CFVEL)
C
C     SUBROUTINE NAME -- INTRP0
C
C     PURPOSE: INTRP0 INTERPOLATES FOR THE POSITION AND VELOCITY
C              COMPONENTS AT A SPECIFIC TIME WITHIN TIME-ORDERED
C              ARRAYS OF POSITION AND VELOCITY DATA, A HERMITE
C              POLYNOMIAL, WHICH CONSIDERS BOTH POSITION AND VELOCITY
C              COMPONENTS, IS USED FOR INTERPOLATION.
C
C     CALLING SEQUENCE -- CALL INTERP0(X,XDOT,K,L,HH,N,TI,XI,XDOTI,
C                                      CFPOS,CFVEL)
C
C       VARIABLE DESCRIPTION
C
C      NAME    TYPE   I/O   DIMENSION   DESCRIPTION
C      X       R*8     I     3,100      ARRAY OF POSITION COMPONENTS
C      XDOT    R*8     I     3,100      ARRAY OF VELOCITY COMPONENTS
C      K       I*4     I        1       STARTING POINT INDEX IN X AND
C                                       XDOT ARRAYS FOR INTERPOLATION
C      L       I*4     I        1       NUMBER OF COORDINATES BEING
C                                       INTERPOLATED
C      HH      R*8     I        1       TIME DIFFERENCE BETWEEN POINTS
C                                       IN X AND XDOT ARRAYS
C      N       I*4     I        1       NUMBER OF POINTS TO BE USED IN
C                                       INTERPOLATION
C      TI      R*8     I        1       TIME DIFFERENCE BETWEEN THE
C                                       VALUES TO BE INTERPOLATED AND
C                                       THE VALUES AT THE STARTING POINT
C                                       SPECIFIED BY K
C      XI      R*8     O        3       INTERPOLATED POSITION COMPONENT
C                                       VALUES
C      XDOTI   R*8     O        3       INTERPOLATED VELOCITY COMPONENT
C                                       VALUES
C      CFPOS   R*8     I        1       CONVERSION FACTOR OF EPHEMERIS
C                                       FILE POSITION DATA TO KM UNITS
C      CFVEL   R*8     I        1       CONVERSION FACTOR OF EPHEMERIS
C                                       FILE VELOCITY DATA TO KM/SEC
C     CALLING ROUTINES: MAIN
C
C     CALLED ROUTINES: NONE
C
C     COMMON BLOCKS REQUIRED: NONE
C
C RESTRICTION
C     MAXIMUM OF 20 POINTS MAY BE USED FOR INTERPOLATION
C
C ORGINATOR
C     MISSION ANALYSIS PROGRAM (MAP)
C
C MODIFICATIONS
C     J GARRAHAN,CSC
C     REDUCE ARRAY SIZE TO 100
C     LIMIT NUMBER OF INTERPOLATION POINTS TO 20
C     ADDED CONVERSION FACTOR FOR POSITION AND VELOCITY DATA
C
      IMPLICIT REAL*8(A-H,O-Z)
      REAL*8 LL
      DIMENSION X(3,100),XDOT(3,100),XI(3),XDOTI(3),
     1 H(2,20),HP(2,20)
C
C  COMPUTE THE NUMBER OF TIME STEPS, S, BETWEEN THE BASE POINT AND THE
C     TIME OF INTERPOLATION
C
      S = +TI / HH
C
C  CHECK TO SEE IF THE DESIRED POINT IS NEAR A GIVEN POINT
C
      V=DABS(DMOD(TI,HH))
      IF(V.GT.1.D-10) GO TO 50
      NPT=DABS(S)+0.5D0
      DO 40 II=1,L
      XI(II)=X(II,K-NPT)/CFPOS
40    XDOTI(II)=XDOT(II,K-NPT)/CFVEL
      RETURN
C
C  INITIALIZE THE COEFFICIENT COUNTER
C
   50 J=1
C
C  INITIALIZE FOR PRODUCT AND SUMS
C
  200 I = 1
      LL=1.D0
      A=0.D0
      B=0.D0
C
C  DETERMINE IF THE COEFFICIENT IS ON THIS LINE
C
  100 IF( I .EQ. J ) GO TO 1000
C
C  DETERMINE THE PRODUCT AND SUMS
C
      LL = LL * (S + I - 1)/(I - J)
      A = A + 1/(S + I - 1)
      B = B + 1.D0/(I-J)
C
C  DETERMINE IF THE PRODUCT AND SUMS ARE COMPLETE
C
 1000 IF( I .EQ. N ) GO TO 2000
C
C  UPDATE COEFFICIENT COUNTER
C
      I = I + 1
      GO TO 100
C
C  COMPUTE THE HERMITE COEFFICIENT FOR LINE J
C
 2000 PHI0 = 1 - 2 * (S + J - 1) * B
      PHI1 = HH * (S + J - 1)
      H(1,J) = PHI0 * LL*LL
      H(2,J) = PHI1 * LL*LL
      G0 = (2/HH) * (A - 2 * A * B * (S + J - 1) - B)
      G1 = 1 + 2 * A * (S + J - 1)
      HP(1,J) = G0 * LL*LL
      HP(2,J) = G1 * LL*LL
C
C  DETERMINE IF ALL OF THE COEFFICIENTS HAVE BEEN COMPUTED
C
      IF(J .EQ. N) GO TO 3000
C
C  UPDATE THE COEFFICIENT COUNTER
C
      J = J + 1
      GO TO 200
C
C  COMPUTE X AND XDOT AT TIME TI
C
 3000 DO 3900 II=1,L
      XI(II) = 0.D0
      XDOTI(II) = 0.D0
      DO 3900 J=1,N
      KMOD=MOD(K-J+1,251)
      IF(KMOD .EQ. 0) KMOD = 251
      XI(II)=H(1,J)*X(II,KMOD)/CFPOS + H(2,J)*XDOT(II,KMOD)/CFVEL
     1  + XI(II)
3900  XDOTI(II)=HP(1,J)*X(II,KMOD)/CFPOS + HP(2,J)*XDOT(II,KMOD)/CFVEL
     1 + XDOTI(II)
      RETURN
      END
